<template>
  <el-select
    ref="select"
    v-model="content"
    filterable
    remote
    multiple
    clearable
    default-first-option
    placeholder="请输入名称搜索"
    :remote-method="remoteMethod"
    :loading="loading"
    v-bind="$attrs"
  >
    <el-option
      v-for="item in list"
      :key="item.oldFacilitiyNo"
      :label="item.oldFacilitiyName"
      :value="item.oldFacilitiyNo"
    >
      <!-- 自定义选择显示值 -->
      <template>
        <div class="itemBox">
          <span>{{ item.oldFacilitiyName }} </span>
          <!-- <span>{{ item.oldFacilitiyNo }}</span> -->
        </div>
      </template>
    </el-option>
  </el-select>
</template>

<script>
/*
选择食堂-多选

import selectCanteenMultiple from '@/components/xm/selectCanteen/selectCanteenMultiple'

<selectCanteenMultiple v-model.trim="model.oldFacilitiyNo" />

*/
import { getDininghallList } from '@/api/happinessCanteen'

export default {
  components: {},
  model: {
    prop: 'oldFacilitiyName',
    event: 'change'
  },
  props: {
    // 搜索名称
    oldFacilitiyName: {
      type: [Array, String],
      default: ''
    }
  },
  data() {
    return {
      loading: false,
      copyList: [],
      list: []
    }
  },
  computed: {
    content: {
      get() {
        return this.oldFacilitiyName
      },
      set(val) {
        this.$emit('change', val)
      }
    }
  },
  mounted() {
    this.getList('', 1)
  },
  methods: {
    // 获取列表
    getList(oldFacilitiyName, isInitLoad) {
      this.loading = true
      getDininghallList({ oldFacilitiyName, pageSize: 200, pageNum: 1, type: '7' }).then(res => {
        if (res.status === 0) {
          this.list = res.data.list || []
          if (isInitLoad) {
            this.copyList = res.data.list || []
          }
        }
      }).finally(() => {
        this.loading = false
      })
    },
    // 远程搜索
    remoteMethod(oldFacilitiyName) {
      this.getList(oldFacilitiyName)
    }
  }
}

</script>
<style scoped lang='scss'>
.el-select{
  width:100%;
}
.itemBox{
  display:flex;
  justify-content:space-between;
}
</style>
